<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Ouwan
 *
 * @author dragon.hu @2016.3.24
 */
require_once 'BaseChannel.php';

//偶玩
class Ouwan implements BaseChannel 
{
	
	function __construct() 
	{
		//echo "construct";
	}

	//put your code here
	function android($data) 
	{
		$paymentKey="ebb43820c094a99f"; //serversecret
		$ret = $this->paymentCallBack($paymentKey, ANDROID);
		echo $ret;
	}

	function ios($data) 
	{
		$paymentKey=""; //
		$ret = $this->paymentCallBack($paymentKey, IOS);
		echo $ret;
	}

	function paymentCallBack($paymentKey, $platform)
	{
		$orderLog = new ChargeOrder();
		$orderLog->log("ouwan", $_REQUEST);
		
		$data = $_REQUEST;
		ksort($data);
		$str = "";
		foreach ($data as $k=>$v)
		{
			if ($k == 'sign')  continue;
			$str .= "{$k}={$v}";
		}
		$str .= $paymentKey;
		$mysign = md5($str);
		
		if($data['sign'] == $mysign)  
		{ //验证通过
			 $tmpstatus = STATUS_SUCCESS;
			 if ($data['orderStatus'] != 1)
			 {
			 	$tmpstatus = STATUS_FAILD;
			 }
			//进行发货
			if(false == $orderLog->recordOrder($tmpstatus, $data['amount'], $data['callbackInfo'], "ouwan", $platform,$data['orderId']))
			{
				$ret="failure";
				$orderLog->log("ouwan",array("order"=>$data['callbackInfo'],"money"=>$data['amount'],"serverresult"=>"faild"));
			}else 
			{
				//支付成功
				$ret="success";
				$orderLog->log("ouwan",array("order"=>$data['callbackInfo'],"money"=>$data['amount'],"serverresult"=>"success"));
			}
		} 
		else 
		{
			//"$sig验证失败"
			$ret="failure";
			$orderLog->log("ouwan"," sign error sign:$sign mysign:$mysign");
		}
		return $ret;
	}
	
}